var util = require('../../libs/util.js');
var app = getApp();
Page({
  data: {
    index: '',
    delivery_date: util.dateObjectformat(new Date(), 'yyyy-MM-dd')
  },
  onShareAppMessage: function () {
    return {
      title: app.appName,
      path: '/pages/index/index'
    }
  },
  onLoad: function (e) {
    wx.setNavigationBarTitle({ "title": app.appName +"--收货点信息" });
    this.setData({
      index: e.index,
      delivery_date: e.delivery_date == 'undefined' ? util.getDateStr(1) : e.delivery_date,
      receive_time: e.receive_time == 'undefined' ? '00:00' : e.receive_time,
      package: e.package == 'undefined' ? '' : e.package,
      goodsInfo: e.goodsInfo == 'undefined' ? '' : e.goodsInfo,
      receiver: e.receiver == 'undefined' ? '' : e.receiver,
      receiver_phone: e.receiver_phone == 'undefined' ? '' : e.receiver_phone
    });
    wx.removeStorage({
      key: 'shopConfig',
      success: function (res) {
      }
    });
  },
  onReady: function () {
    wx.hideToast()
  },
  bindInput: function (e) {
    var item = String(e.currentTarget.id), item_value = {};
    item_value[item] = e.detail.value;
    this.setData(item_value);
  },
  confirmData: function () {
    // if (!this.data.delivery_date || !this.data.receive_time) {
    //   wx.showToast({
    //     title: "有未输入项",
    //     image: "/images/wrong.svg",
    //     duration: 3000
    //   });
    //   return false;
    // };
    wx.setStorage({
      key: "shopConfig",
      data: { 
        alias: this.data.alias, 
        delivery_date: this.data.delivery_date, 
        receive_time: this.data.receive_time,
        package: this.data.package,
        goodsInfo: this.data.goodsInfo, 
        receiver: this.data.receiver, 
        receiver_phone: this.data.receiver_phone, 
        index: this.data.index 
        }
    });
    wx.navigateBack({
      delta: 1
    });
  },
  cancelConfirmData: function () {
    wx.navigateBack({
      delta: 1
    });
  }
});